package org.insidesource.flexbugs.client;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.insidesource.flexbugs.model.Comment;
import org.insidesource.flexbugs.model.Issue;
import org.insidesource.flexbugs.service.CommentManager;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestClient
{
//	@PersistenceContext(unitName="FlexBugsPU")
//	private EntityManager mysqlEm;
	
	public void test()
	{
		EntityManagerFactory mysql = Persistence.createEntityManagerFactory("FlexBugsPU");
		System.out.println("persistence unit: " + mysql);
		
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		CommentManager commentService = (CommentManager)context.getBean("commentServiceJpa");
		Comment comment = new Comment();
		comment.setAuthor("mac");
		comment.setAuthor("test");
		commentService.save(comment);
		
		commentService = (CommentManager)context.getBean("commentService");
		comment = new Comment();
		Issue issue = new Issue();
		issue.setId(1L);
		comment.setIssue(issue);
		comment.setAuthor("mac");
		comment.setAuthor("test");
		commentService.save(comment);
	}
}
